package ir.blocks;

import ir.Block;
import ir.StructuralDefinition;

import java.util.LinkedList;
import java.util.List;

import run.Facet;

/**
 * A block representing a list of Facets
 * e.g.: 
 * 		(.a, .b, .c)
 * @author Thomas Chau
 *
 */
public class FacetsBlk extends Block {

	List<String> facetNames;
	List<Facet> realFacets;
	UnitBlk owner;
	
	public FacetsBlk(List<String> facets) {
		this.facetNames = facets;
	}

	/**
	 * Return facets of the owning structural definition.
	 */
	@Override
	public List<Facet> getLeftFacets(
			StructuralDefinition d) {
		LinkedList<Facet> facets = new LinkedList<Facet>();
		for (String name : facetNames) {
			Facet facet = d.getFacet(name, false);
			facets.add(facet);
		}
		
		return facets;
	}

	/**
	 * Return uncontextualized facets.
	 */
	@Override
	public List<Facet> getRightFacets(
			StructuralDefinition d) {
		LinkedList<Facet> facets = new LinkedList<Facet>();
		for (String name : facetNames) {
			Facet facet = d.getFacet(name, true);
			facets.add(facet);
		}
		
		return facets;
	}
	
	public String toString() {
		String s = "";
		for (String f : facetNames) {
			s += f + " ";
		}
		return s;
				
	}

	public void setOwner(UnitBlk owner) {
		this.owner = owner;
	}

	public boolean contains(String name) {
		return facetNames.contains(name);
	}

	@Override
	public FacetsBlk clone() {
		FacetsBlk facetsBlk = new FacetsBlk(facetNames);
		
		if (owner != null)
			facetsBlk.setOwner(owner.clone());
		return facetsBlk;
	}
	

}
